using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Constant;
using System.Xml.Serialization;

namespace Pixysoft.Weblications.Sango.Battle
{
    /** (actiontype, attacker), skill/attack, items */
    class BattleActionHistory
    {
        int actionTypeCode;
        long skilltypecode;
        long attacktypecode;

        BattlerHistory attacker = null;

        List<BattleActionItemHistory> items = new List<BattleActionItemHistory>();

        public BattleActionHistory()
        {
        }

        /** setDefenser, setHistoryCode */
        public BattleActionItemHistory createItem(Battler defenser, int actionResult)
        {
            BattleActionItemHistory item = new BattleActionItemHistory(defenser, actionResult);
            this.items.Add(item);
            return item;
        }

        public void setAttacker(BattlerHistory attacker)
        {
            this.attacker = attacker;
        }

        public void setAttack(IBattleAttack attack)
        {
            this.attacktypecode = attack.getAttackTypeCode();
        }

        public void setSkill(IBattleSkill skill)
        {
            this.skilltypecode = skill.getSkillTypeCode();
        }


        [XmlAttribute("action")]
        public int ActionTypeCode
        {
            get { return actionTypeCode; }
            set { actionTypeCode = value; }
        }

        [XmlAttribute("skill")]
        public long Skilltypecode
        {
            get { return skilltypecode; }
            set { skilltypecode = value; }
        }

        [XmlAttribute("attack")]
        public long Attacktypecode
        {
            get { return attacktypecode; }
            set { attacktypecode = value; }
        }

        public BattlerHistory Attacker
        {
            get { return attacker; }
            set { attacker = value; }
        }

        public List<BattleActionItemHistory> Items
        {
            get { return items; }
            set { items = value; }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("ATTACKER: ").Append(attacker.BattlerCode)//
                    .Append(". TYPE: " + BattleActionTypecodeCollection.getComment(this.actionTypeCode))//
                    .Append(". ATTACKTYPE: " + AttackTypecodeCollection.getComment(this.attacktypecode))//
                    .Append(". SKILLTYPE: " + SkillTypecodeCollection.getComment(this.skilltypecode))//
                    .Append("\n");

            foreach (BattleActionItemHistory item in items)
            {
                builder.Append(item.ToString());
            }

            builder.Append("--------------------").Append("\n");

            return builder.ToString();
        }
    }
}